#include "MBVec2.h"

#include <cstring>

/**
  * Constructs a new MBVec2 object with coordinates (0 0)
  */
MBVec2::MBVec2( void )
{
	mValues[0] = 0.0;
	mValues[1] = 0.0;
}

/**
  * Constructs a new MBVec2 object with the coordinates of the given double array
  *
  * @param values const pointer to the first element of a double array with two elements
  */
MBVec2::MBVec2( const double *values )
{
	memcpy( mValues, values, 2 * sizeof( double ) );
}

/**
  * Constructs a new MBVec2 object with the given coordinates
  *
  * @param v1 element v1
  * @param v2 element v2
  */
MBVec2::MBVec2( const double &v1, const double &v2 )
{
	mValues[0] = v1;
	mValues[1] = v2;
}

/**
  * Returns a reference to the element at index
  *
  * @param index index of the element (0 or 1)
  * @return reference to the element at index
  */
double &MBVec2::operator[]( const MBuint &index )
{
	return mValues[index];
}

/**
  * Returns a const reference to the element at index
  *
  * @param index index of the element (0 or 1)
  * @return const reference to the element at index
  */
const double &MBVec2::operator[]( const MBuint &index ) const
{
	return mValues[index];
}

bool MBVec2::operator==(const MBVec2 &other) const
{
	return (mValues[0] == other[0]) && (mValues[1] == other[1]);
}